#pragma once

#include <NImages.h>
#include <NMediaSource.h>
#include <NMediaReader.h>
#include <NVideoFormat.h>
#include <NAudioFormat.h>
#include <NLicensing.h>
#include <NVideoReader.h>

#include <string>

class apSSVideoReader
{
public:
	apSSVideoReader(void);
	~apSSVideoReader(void);
	bool		Init(const char* filename, bool bLive = false);
	bool		Init2(const char* filename);
	int			GetWidth(){return m_width;}
	int			GetHeight(){return m_height;}
	double		GetFrameRate(){return m_framerate;}
	LONGLONG	GetDuration(){return m_duration;}
	int			GetFramCnt(){return m_frameCnt;}

	bool ReadFrame(HNImage *pHImage, HBITMAP *phBmp, LONGLONG *timeStamp);
	bool ReadFrame2(HNImage *pHImage, int frameNo);
	bool SeekTo(LONGLONG time);
	bool GetPos(LONGLONG *pTime);
	bool SaveFrame(const char *filename, LONGLONG *pTime);
	void Close();
private:
	bool GetVideoInfo();
private:
	HNMediaSource		m_hSource;
	HNMediaReader		m_hReader;
	//HNImage				m_hImage;
	NLong				m_duration;
	std::string			m_clipname;
	int					m_width;
	int					m_height;
	double				m_framerate;
	bool				m_inited;
	
	//version 2
	HNVideoReader		m_hReader2;
	int					m_frameCnt;
};
